package com.ruoyi.assets.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.assets.domain.AssetCategories;
import com.ruoyi.assets.service.IAssetCategoriesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 资产类别Controller
 * 
 * @author sfk
 * @date 2025-03-03
 */
@RestController
@RequestMapping("/categories")
public class AssetCategoriesController extends BaseController
{
    @Autowired
    private IAssetCategoriesService assetCategoriesService;

    /**
     * 查询资产类别列表
     */
    @RequiresPermissions("assets:categories:list")
    @GetMapping("/list")
    public TableDataInfo list(AssetCategories assetCategories)
    {
        startPage();
        List<AssetCategories> list = assetCategoriesService.selectAssetCategoriesList(assetCategories);
        return getDataTable(list);
    }

    /**
     * 导出资产类别列表
     */
    @RequiresPermissions("assets:categories:export")
    @Log(title = "资产类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetCategories assetCategories)
    {
        List<AssetCategories> list = assetCategoriesService.selectAssetCategoriesList(assetCategories);
        ExcelUtil<AssetCategories> util = new ExcelUtil<AssetCategories>(AssetCategories.class);
        util.exportExcel(response, list, "资产类别数据");
    }

    /**
     * 获取资产类别详细信息
     */
    @RequiresPermissions("assets:categories:query")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(assetCategoriesService.selectAssetCategoriesByCategoryId(categoryId));
    }

    /**
     * 新增资产类别
     */
    @RequiresPermissions("assets:categories:add")
    @Log(title = "资产类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetCategories assetCategories)
    {
        return toAjax(assetCategoriesService.insertAssetCategories(assetCategories));
    }

    /**
     * 修改资产类别
     */
    @RequiresPermissions("assets:categories:edit")
    @Log(title = "资产类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetCategories assetCategories)
    {
        return toAjax(assetCategoriesService.updateAssetCategories(assetCategories));
    }

    /**
     * 删除资产类别
     */
    @RequiresPermissions("assets:categories:remove")
    @Log(title = "资产类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(assetCategoriesService.deleteAssetCategoriesByCategoryIds(categoryIds));
    }

    /**
     * ；批量修改状态：启用
     */
//    @RequiresPermissions("assets:categories:remove")
//    @Log(title = "资产类别", businessType = BusinessType.DELETE)
    @PostMapping("/startStatusAssets/{categoryIds}")
    public AjaxResult startStatusAssets(@Valid @PathVariable Long[] categoryIds)
    {
        return toAjax(assetCategoriesService.startStatusAssets(categoryIds));
    }

    /**
     * ；批量修改状态：禁用
     */
    @PostMapping("/endStatusAssets/{categoryIds}")
    public AjaxResult endStatusAssets(@Valid @PathVariable Long[] categoryIds)
    {
        return toAjax(assetCategoriesService.endStatusAssets(categoryIds));
    }

    /**
     * 查询资产类别
     */
//    @RequiresPermissions("assets:categories:list")
    @GetMapping("/searchCategoriesList")
    public AjaxResult searchCategoriesList(AssetCategories assetCategories)
    {
        List<AssetCategories> list = assetCategoriesService.selectAssetCategoriesList(assetCategories);
        return success(list);
    }
}
